package top.wilbert.collegelink.user.service.impl;

import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import top.wilbert.collegelink.common.utils.PageUtils;
import top.wilbert.collegelink.common.utils.Query;

import top.wilbert.collegelink.user.dao.CompanyCertificationDao;
import top.wilbert.collegelink.user.entity.CompanyCertificationEntity;
import top.wilbert.collegelink.user.service.CompanyCertificationService;


@Service("companyCertificationService")
public class CompanyCertificationServiceImpl extends ServiceImpl<CompanyCertificationDao, CompanyCertificationEntity> implements CompanyCertificationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CompanyCertificationEntity> page = this.page(
                new Query<CompanyCertificationEntity>().getPage(params),
                new QueryWrapper<CompanyCertificationEntity>()
        );
        Date date = new Date(System.currentTimeMillis());

        List<CompanyCertificationEntity> records = page.getRecords();

        for ( CompanyCertificationEntity one : records) {
          if ((date.getTime() - one.getCreateTime().getTime()) > 3 * 24 * 60 * 60 * 1000 ){

              one.setIsOk(0);
              baseMapper.updateById(one);
          }
        }

        List<CompanyCertificationEntity> collect = records.stream().filter(s -> s.getIsOk() != 0).collect(Collectors.toList());

        page.setRecords(collect);
        return new PageUtils(page);
    }

}